export function getshowtime(time) {
  let createTime
  if (typeof time === 'number') {
    createTime = new Date(parseInt(time))
  } else if (typeof time === 'string') {
    createTime = new Date(time)
  }
  

  let createTimes = createTime.getTime()
  let nowTime = new Date()
  let nowTimes = nowTime.getTime()
  if (nowTimes < createTimes) {
    return `现在时间之后`
  }

  let createYear = createTime.getFullYear()
  let nowYear = nowTime.getFullYear()
  let createMonth = createTime.getMonth()
  let nowMonth = nowTime.getMonth()
  let createDate = createTime.getDate()
  let nowDate = nowTime.getDate()

  if (createYear < nowYear) {
    return `${nowYear - createYear}年前`
  } else {
    if (createMonth < nowMonth) {
      return `${nowMonth - createMonth}月前`
    } else {
      if (createDate < nowDate) {
        if (nowDate - createDate == 1) {
          let min = createTime.getMinutes()
          let hour = createTime.getHours()
          return `昨天 ${hour < 10 ? '0'+hour : hour}:${min < 10 ? '0'+min : min}`
        } else {
          return `${nowDate - createDate}天前`
        }
      } else {
        // 当天
        let diffValue = nowTimes - createTimes
        if (diffValue / (1000 * 60 * 60) >= 1) {
          return `${parseInt(diffValue / (1000 * 60 * 60))}小时前`
        } else {
          if (diffValue / (1000 * 60) >= 1) {
            return `${parseInt(diffValue / (1000 * 60))}分钟前`
          } else {
            return `刚刚`
          }
        }
      }
    }
  }
}

export function getIcon(url) {
  let patt1 = /(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/
  let arr = url.match(patt1)
  let domain = arr[2].split('.')
  return `${arr[1]}://www.${domain[domain.length - 2]}.${domain[domain.length - 1]}/favicon.ico`
}